#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <math.h>

int main()
{
    int fd_lcd;
    fd_lcd = open("/dev/fb0", O_RDWR);

    if (fd_lcd < 0)
    {
        printf("open lcd error: %s\n", strerror(errno));
        return -1;
    }
    printf("open lcd success\n");

    // 映射内存  lcd_mmap int类型的指针  800*480*4字节
    int (*lcd_mmap)[800] = mmap(NULL, 800 * 480 * 4, PROT_READ | PROT_WRITE, MAP_SHARED, fd_lcd, 0);
    printf("mmap success\n");
    memset(lcd_mmap, 0, 800 * 480 * 4);

    for (int row = 0; row < 480; row++)
    {
        for (int col = 0; col < 800; col++)
        {
            int x = col - 200;
            int y = row - 200;
            if (pow(x, 2) + pow(y, 2) <= 100 * 100)
            {
                lcd_mmap[row][col] = 0x00ff0000;
            }
        }
    }

    munmap(lcd_mmap, 800 * 480 * 4);

    close(fd_lcd);
    return 0;
}
